using System;
using System.Reflection;
using SwinGame;
using Color = System.Drawing.Color;
using System.Collections.Generic;

namespace solid_test.src
{
    public interface IEntityPosition<t>
    {
        void setPosition(t x, t y, bool relative = false);
        t[] getPosition();
    }

    //modifies unit position//
    public class UnitPosition : IEntityPosition<float>
    {
        float _x;
        float _y;
        public void setPosition(float x, float y, bool relative = false)
        {
            if (relative) { _x += x; _y += y; Console.WriteLine(_x + " " + _y); }
            else{ _x = x; _y = y;}
        }
        public float[] getPosition() { return new float[2] { _y, _x }; }
        public UnitPosition(float x, float y) { setPosition(x, y, false); }
    }

    public interface IEntityData<t>
    {
        void setMax(t maxData);
        void set(t data);
        t getMax();
        t get();
    }

    public class Health : IEntityData<float>
    {
        float _health;
        float _maxHealth;

        public void set(float health) { _health = health; }
        public void setMax(float maxHealth) { _maxHealth = maxHealth; }
        public float get() { return _health; }
        public float getMax() { return _maxHealth; }
    }

    public class Mana : IEntityData<float>
    {
        float   _mana;
        float   _maxMana;

        public void set(float mana) { _mana = mana; }
        public void setMax(float maxMana) { _maxMana = maxMana; }
        public float get() { return _mana; }
        public float getMax() { return _maxMana; }
    }

    public interface IEntitySprite
    {
        void setSprite(string filename);
        Sprite getSprite();
        void DrawSprite(int x, int y);
    }
    public class UnitSprite : IEntitySprite
    {
        Sprite  _sprite;

        public void setSprite(string filename) { _sprite = new Sprite(new Bitmap(filename)); }
        public Sprite getSprite() { return _sprite; }
        public void DrawSprite(int x, int y) { _sprite.Draw(x,y); }
        public UnitSprite(string path) { setSprite(path); }
    }


    public interface IEntityModel
    {
        void Update(double dt);
       // void Move(int x, int y);//
    }

    public class UnitModel : IEntityModel
    {
        IEntityPosition<float> _currentPos;
        IEntitySprite _sprite;

        public void Move(int x, int y) { _currentPos.setPosition(x, y, true); }

        public void Update(double dt)
        {
            _sprite.DrawSprite((int)_currentPos.getPosition()[1], (int)_currentPos.getPosition()[0]);
        }

        public UnitModel(float x, float y, string sprite_path)
        {
            _currentPos = new UnitPosition(x, y);
            _sprite = new UnitSprite("alpha.png");
        }
    }

    public interface IEntityController
    {
        void getInput();
    }

    public class UnitController : IEntityController
    {
        UnitModel _model;

        public void getInput()
        {
            if (SwinGame.Input.KeyDown(KeyCode.vk_LEFT)){_model.Move(-1, 0);}
            if (SwinGame.Input.KeyDown(KeyCode.vk_RIGHT)){_model.Move(1, 0);}
            if (SwinGame.Input.KeyDown(KeyCode.vk_UP)) { _model.Move(0, -1); }
            if (SwinGame.Input.KeyDown(KeyCode.vk_DOWN)) { _model.Move(0, 1); }
            //if paused? dt 
            _model.Update(1);
        }
        public UnitController(){_model = new UnitModel(0,0,"Hello World.png");}

    }

    public interface IEntityView
    {
        void SeeUser();
    }

    public class UnitView : IEntityView
    {
        IEntityController _controller;

        public void SeeUser()
        {
            _controller.getInput();
        }

        public UnitView() { _controller = new UnitController(); }

    }

    //public interface IEntity
    //{
    //    //List<IEntityData<float>> getFloatData();
    //    //IEntityPosition<int> getIntPosition();
    //    //IEntitySprite getSprite();
    //    //IEntityModel getModel();
    //    IEntityController getController();
    //}

    //public class Entity //: IEntity
    //{
    //    //stats//
    //    //List<IEntityData<float>> _data;
    //    //position//
    //    //IEntityPosition<int> _pos;
    //    //sprite//
    //    //IEntitySprite _sprite;
    //    //controller
    //    IEntityController _controller;
    //    //Model
    //    //IEntityModel _model;

    //    #region IEntity
    //    //public List<IEntityData<float>> getFloatData() { return _data; }
    //    //public IEntityPosition<int> getIntPosition() { return _pos; }
    //    //public IEntitySprite getSprite() { return _sprite; }
    //    //public IEntityModel getModel() { return _model; }
    //    public IEntityController getController() { return _controller; }
    //    #endregion
    //}

    public class Unit
    {
        
    }

    public class GameMain
    {
        public static void Main()
        {
            //Start the audio system so sound can be played
            Audio.OpenAudio();
            UnitView uv = new UnitView();
            //Open the game window
            Graphics.OpenGraphicsWindow("GameMain", 800, 600);
            Graphics.ShowSwinGameSplashScreen();

            //Run the game loop
            while (false == Input.WindowCloseRequested())
            {
                //Fetch the next batch of UI interaction
                Input.ProcessEvents();
               
                //Clear the screen and draw the framerate
                Graphics.ClearScreen(Color.White);

                uv.SeeUser();
                Text.DrawFramerate(0, 0);

                //Draw onto the screen
                Graphics.RefreshScreen();
            }

            //End the audio
            Audio.CloseAudio();

            //Close any resources we were using
            Resources.ReleaseAllResources();
        }
    }
}